package com.taotao.sso.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.sso.pojo.User;
import com.taotao.sso.service.UserService;

@RequestMapping("user")
@Controller
public class UserController {
	
	@Autowired
	private UserService userService;
	

	
	
	
	
	@RequestMapping(value="login",method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> login(@RequestParam("u")String username,@RequestParam("p")String password){
		try {
			User user=new User();
			user.setUsername(username);
			user.setPassword(password);
			
			String ticket=this.userService.login(user);
			if(ticket==null){
				//登录失败
				return ResponseEntity.status(HttpStatus.OK).body(null);
			}
			
			
			return ResponseEntity.status(HttpStatus.OK).body(ticket);
		} catch (Exception e) {
		
			e.printStackTrace();
			return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
		}
		
	}
	
	

}
